<?php
class CommentAction extends HomeAction{

	//评论管理
	public function index(){
		$list=$this->_select('comment','',5);

		$article=M('Article');

		import('ORG.Net.IpLocation');	//导入IP类
		$Ip = new IpLocation('UTFWry.dat');
		foreach($list as $key => $val){
			$res=$article->field('title')->find($val['comm_content_id']);
			$list[$key]['title']=$res['title'];
			$list[$key]['statusname']=($val['status']==1)?'已审核':'未审核';
			$ipaddress=$Ip->getlocation($val['ip']);
			$list[$key]['ipaddress']=$ipaddress['country'].'，'.$ipaddress['area'];
		}
		$this->assign('list',$list);
		$this->display();
	}

	//切换评论状态
	public function status(){
		$comment=M('Comment');
		$id=$this->_get('id');		//评论ID
		$val=$this->_get('val');	//获得状态值
		$val=($val==2)?1:2;		//切换值

		$data['status']=$val;
		$result=$comment->where('id='.$id)->save($data);
		if($result){
			$this->success('审核状态已变更');
		}else{
			$this->error('审核状态切换失败');
		}
	}

	//删除评论
	public function del(){
		$id=$this->_get('id');
		$comment=M('Comment');
		$result=$comment->delete($id);

		if($result){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}

}